import React, { Component } from 'react';
import '../pages/Order/Order.css'
import { withRouter } from 'react-router-dom'
import aa from '../uitls/session'
// import ShopList from './ShopList'

class Orderlist extends Component {
    constructor() {
        super()
        this.state = {
            shopList: [],
        }
    }
    pingjia = (orderid) => {
        // console.log(orderid);
        aa.setStorage('order', orderid)
        this.props.history.push({ pathname: "/Home/HCcustomerEvaluation/"+orderid}) 
    }
    againSingle = (shop_id, orderInfo) => {
        // console.log(shop_id);//商店id
        // console.log(orderInfo);//该订单对应的商品信息
        this.props.history.push({ pathname: "/Home/ShopDetails/"+ shop_id})

    }
    openOrder = (orderId) => {
        // console.log(orderId);
        aa.setStorage('order', orderId)
        this.props.history.push({ pathname: "/Home/OrderDetails" })
    }
    drawingShop(shop) {
        return shop.map((item,index) => <div key={index+'shangpin'}>
            <div className='content_img'><img src="../../../imges/kfcgoods1.jpg" alt="" /></div>
            <p>{item.goods.goods_name}</p>
        </div>)
    }
    showPing(status, orderid,order_evaluation) {
        if (status === '已完成' && order_evaluation==='待评价') {
            return (<div onClick={() => this.pingjia(orderid)}><span>去评价</span></div>)
        }
    }

    // 数组对象根据某个字段去重，参数传数组和对应的字段
    // unique(arr,val) {
    //     const res = new Map();
    //     return arr.filter(item => !res.has(item[val]) && res.set(item[val], 1))
    // }
    render() {
        let orderList = []
        if (this.props.data.length) {
            orderList = this.props.data.map((item) => <div key={item.order_id} className='content'>
                <div className='content_header'>
                    <div className='storename'>
                        <div className='img'><img src="../../../imges/kfct.jpg" alt="" /></div>
                        <div>
                            <div><span>{item.shop1.shop_name}</span></div>
                            <div className='activity'><span>99减10</span></div>
                        </div>
                        <div><span className='iconfont icon-iconfontyoujiantou-zuo'></span></div>
                    </div>
                    <div><span>{item.orderStatus.order_status_name}</span></div>
                </div>
                <div className='content_order' onClick={() => this.openOrder(item.order_id)}>
                    <div className='price'>
                        <p>￥{item.order_money}</p>
                        <p>共{item.order_num}件</p>
                    </div>
                    <div className='content_order1'>
                        {/* <ShopList data={item.orderInfo}></ShopList> */} 
                        {this.drawingShop(item.orderInfo)}
                        <div>
                            <div className='kongbai'></div>
                        </div>
                    </div>
                </div>
                <div className='content_evaluation'>
                    <div onClick={() => this.againSingle(item.shop1.shop_id, item.orderInfo)}><span>再来一单</span></div>
                    {this.showPing(item.orderStatus.order_status_name, item.order_id,item.order_evaluation)}
                </div>
            </div>)

        } else {
            orderList = <h3>暂无数据</h3>
        }

        return (
            <div>
                {orderList}
            </div>
        );
    }
}

export default withRouter(Orderlist);